/*******************************************************************************
 * Copyright (c) 2008, 2009 Tapestry IDE Developers
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Tapestry IDE Developers - initial API and implementation
 *******************************************************************************/
package com.googlecode.tapestry.ide.core.model;

/**
 * Default implementation of the common protocol for all model elements that map
 * to a resource in the Eclipse workspace.
 */
public abstract class AbstractResourceModelElement extends AbstractModelElement
		implements IResourceModelElement {

	/**
	 * Instantiates a new abstract resource model element.
	 * 
	 * @param parent
	 *            the parent
	 * @param name
	 *            the name
	 */
	protected AbstractResourceModelElement(IModelElement parent, String name) {
		super(parent, name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.googlecode.tapestry.ide.core.model.AbstractModelElement#equals(java
	 * .lang .Object)
	 */
	@Override
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof AbstractResourceModelElement)) {
			return false;
		}
		AbstractResourceModelElement that = (AbstractResourceModelElement) other;
		if (this.getElementResource() == that.getElementResource()) {
			return true;
		}
		if (this.getElementResource() == null
				|| that.getElementResource() == null) {
			return false;
		}
		if (this.getElementResource().equals(that.getElementResource())) {
			return true;
		}
		return super.equals(other);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.googlecode.tapestry.ide.core.model.AbstractModelElement#hashCode()
	 */
	@Override
	public int hashCode() {
		int hashCode = 0;
		if (getElementResource() != null) {
			hashCode = getElementResource().hashCode();
		}
		return 29 * hashCode + super.hashCode();
	}
}
